<?php
namespace Services\Api;
use Common\Common;
use Common\Models\OrderCommissions;
use Common\Models\Wallets;
use Services\ServicesApiBase;
class SelfCenterServices extends ServicesApiBase
{
    /**
     * 收益列表
     * @param $userInfo
     * @return mixed
     */
    public function getInfoNew($userInfo){
        $wallets       = new Wallets();
        $user_wallerts = $wallets->findbyUserId((int)$userInfo['id']);
        if (empty($user_wallerts)) {
            $data['amount'] = "0.00";      //可提现
        } else {
            $data['amount'] = $user_wallerts->amount;      //可提现
        }
        $orderCommission    = new OrderCommissions();
        $allEstimate = $orderCommission->all_pre_no_goods($userInfo['id']);
        $data['all_month']  = Common::bc($allEstimate,0,'+');

        //我的推广
        $start_end_time               = Common::timeChange(1);  //今日的收益
        $today_mine_assoc             = $this->statisticsCount_new((int)$userInfo['id'], $start_end_time, 'today');
        $data['mine']['today']        = $today_mine_assoc['self'];
        $data['association']['today'] = $today_mine_assoc['assoc'];


        $start_end_time                   = Common::timeChange(2);  //昨日的收益
        $yesterday_mine_assoc             = $this->statisticsCount_new((int)$userInfo['id'], $start_end_time, 'yesterday');
        $data['mine']['yesterday']        = $yesterday_mine_assoc['self'];
        $data['association']['yesterday'] = $yesterday_mine_assoc['assoc'];

        $start_end_time               = Common::timeChange(8);  //本月的收益
        $month_mine_assoc             = $this->statisticsCount_new((int)$userInfo['id'], $start_end_time, 'month');
        $data['mine']['month']        = $month_mine_assoc['self'];
        $data['association']['month'] = $month_mine_assoc['assoc'];

        $start_end_time                   = Common::timeChange(9);  //上月的收益
        $lastmonth_mine_assoc             = $this->statisticsCount_new((int)$userInfo['id'], $start_end_time, 'lastmonth');
        $data['mine']['lastmonth']        = $lastmonth_mine_assoc['self'];
        $data['association']['lastmonth'] = $lastmonth_mine_assoc['assoc'];
        return $data;
    }




    /**
     * @func 获取统计数据
     * @param $user_id 用户id
     * @param $start_end_time 时间节点
     * @param $flag 日期标识
     */
    public function statisticsCount_new($user_id, $start_end_time, $flag = '')
    {

        $orderCommission = new OrderCommissions();
        //订单数量
        $self_count      = $orderCommission->getOrderCount($user_id, $start_end_time);        //自购订单数
        $selftaobaoCount = isset($self_count['haodanku']) ? $self_count['haodanku'] . '' : '0';      //自己淘宝的订单数
        $selfjdCount     = isset($self_count['jd']) ? $self_count['jd'] . '' : '0';                  //自己京东的订单数
        $selfpddCount    = isset($self_count['pdd']) ? $self_count['pdd'] . '' : '0';   //自己拼多多的订单数
        $selfvphCount    = isset($self_count['vph']) ? $self_count['vph'] . '' : '0';   //自己唯品会的订单数
        $selfsuningCount = isset($self_count['suning']) ? $self_count['suning'] . '' : '0';   //自己的订单数
//        $selfduomaiCount = isset($self_count[Common::DUOMAI]) ? $self_count[Common::DUOMAI] . '' : '0';   //自己的订单数
//        $selfelmCount    = isset($self_count[Common::ELM]) ? $self_count[Common::ELM] . '' : '0';   //自己的订单数

        $fans_count      = $orderCommission->getFansOrderCounts($user_id, $start_end_time);        //粉丝订单数
        $fanstaobaoCount = isset($fans_count['haodanku']) ? $fans_count['haodanku'] . '' : '0';  //粉丝淘宝订单
        $fansjdCount     = isset($fans_count['jd']) ? $fans_count['jd'] . '' : '0';
        $fanspddCount    = isset($fans_count['pdd']) ? $fans_count['pdd'] . '' : '0';
        $fansvphCount    = isset($fans_count['vph']) ? $fans_count['vph'] . '' : '0';
        $fanssuningCount = isset($fans_count['suning']) ? $fans_count['suning'] . '' : '0';
//        $fansduomaiCount = isset($fans_count[Common::DUOMAI]) ? $fans_count[Common::DUOMAI] . '' : '0';   //自己的订单数
//        $fanselmCount    = isset($fans_count[Common::ELM]) ? $fans_count[Common::ELM] . '' : '0';   //自己的订单数

        //订单金额
        $data_params['buyer_id'] = $user_id;                //自购订单
        $self_money              = $orderCommission->getOrderChannelEstimateCommission($user_id, $start_end_time, '', $data_params);        //自购订单数
        $self_taobao_moeny       = isset($self_money['haodanku']) ? Common::number_randtwo($self_money['haodanku']) : '0.00';      //自己淘宝的订单数
        $self_jd_money           = isset($self_money['jd']) ? Common::number_randtwo($self_money['jd']) : '0.00';                  //自己京东的订单数
        $self_pdd_money          = isset($self_money['pdd']) ? Common::number_randtwo($self_money['pdd']) : '0.00';   //自己拼多多的订单数
        $self_vph_money          = isset($self_money['vph']) ? Common::number_randtwo($self_money['vph']) : '0.00';   //自己拼多多的订单数
        $self_suning_money       = isset($self_money['suning']) ? Common::number_randtwo($self_money['suning']) : '0.00';   //自己拼多多的订单数
//        $self_duomai_money       = isset($self_money[Common::DUOMAI]) ? Common::number_randtwo($self_money[Common::DUOMAI]) : '0.00';   //自己拼多多的订单数
//        $self_elm_money          = isset($self_money[Common::ELM]) ? Common::number_randtwo($self_money[Common::ELM]) : '0.00';   //自己拼多多的订单数

        $nodata_params['nobuyer_id'] = $user_id;              //粉丝订单
        $fans_money                  = $orderCommission->getOrderChannelEstimateCommission($user_id, $start_end_time, '', $nodata_params);        //粉丝订单数
        $fans_taobao_money           = isset($fans_money['haodanku']) ? Common::number_randtwo($fans_money['haodanku']) : '0.00';  //粉丝淘宝订单
        $fans_jd_money               = isset($fans_money['jd']) ? Common::number_randtwo($fans_money['jd']) : '0.00';
        $fans_pdd_money              = isset($fans_money['pdd']) ? Common::number_randtwo($fans_money['pdd']) : '0.00';
        $fans_vph_money              = isset($fans_money['vph']) ? Common::number_randtwo($fans_money['vph']) : '0.00';
        $fans_suning_money           = isset($fans_money['suning']) ? Common::number_randtwo($fans_money['suning']) : '0.00';
//        $fans_duomai_money           = isset($fans_money[Common::DUOMAI]) ? Common::number_randtwo($fans_money[Common::DUOMAI]) : '0.00';
//        $fans_elm_money              = isset($fans_money[Common::ELM]) ? Common::number_randtwo($fans_money[Common::ELM]) : '0.00';

        //$data['self']['money'] = Common::number_randtwo($self_taobao_moeny + $self_jd_money + $self_pdd_money + $fans_taobao_money + $fans_jd_money + $fans_pdd_money + $self_vph_money + $fans_vph_money + $self_suning_money + $fans_suning_money+$self_duomai_money + $self_elm_money);
        $data['self']['money'] = Common::number_randtwo($self_taobao_moeny + $self_jd_money + $self_pdd_money + $fans_taobao_money + $fans_jd_money + $fans_pdd_money + $self_vph_money + $self_suning_money);
        $data['estimate']      = Common::number_randtwo($orderCommission->getOrderSettlementCommission_new3($user_id, $start_end_time));    //结算预估佣金

        $data['self']['deatil'][] = ['name' => '淘宝', 'count' => $selftaobaoCount, 'money' => $self_taobao_moeny];
        $data['self']['deatil'][] = ['name' => '京东', 'count' => $selfjdCount, 'money' => $self_jd_money];
        $data['self']['deatil'][] = ['name' => '拼多多', 'count' => $selfpddCount, 'money' => $self_pdd_money];
        $data['self']['deatil'][] = ['name' => '唯品会', 'count' => $selfvphCount, 'money' => $self_vph_money];
        $data['self']['deatil'][] = ['name' => '苏宁', 'count' => $selfsuningCount, 'money' => $self_suning_money];
//        $data['self']['deatil'][] = ['name' => '其他', 'count' => $selfduomaiCount + $selfelmCount, 'money' => $self_duomai_money + $self_elm_money];

        $data['assoc']['deatil'][] = ['name' => '淘宝', 'count' => $fanstaobaoCount, 'money' => $fans_taobao_money];
        $data['assoc']['deatil'][] = ['name' => '京东', 'count' => $fansjdCount, 'money' => $fans_jd_money];
        $data['assoc']['deatil'][] = ['name' => '拼多多', 'count' => $fanspddCount, 'money' => $fans_pdd_money];
        $data['assoc']['deatil'][] = ['name' => '唯品会', 'count' => $fansvphCount, 'money' => $fans_vph_money];
        $data['assoc']['deatil'][] = ['name' => '苏宁', 'count' => $fanssuningCount, 'money' => $fans_suning_money];
//        $data['assoc']['deatil'][] = ['name' => '其他', 'count' => $fansduomaiCount + $fanselmCount, 'money' => $fans_duomai_money + $fans_elm_money];
        return $data;
    }



    /**
     * 设置用户标签
     */
    public function tagList(){
//     itemList = [
//	{
//        title: '性别',
//		type: 'gender',
//		item: [
//			{
//                value: 0,
//				name: '女',
//				type: 'gender',
//				checked: true
//			},
//			{
//                value: 1,
//				name: '男',
//				type: 'gender',
//				checked: false
//			}
//		]
//	},
//	{
//        title: '婚育',
//		type: 'isWed',
//		item: [
//			{
//                value: 0,
//				name: '单身',
//				type: 'isWed',
//				checked: true
//			},
//			{
//                value: 1,
//				name: '恋爱',
//				type: 'isWed',
//				checked: false
//			},
//			{
//                value: 2,
//				name: '已婚',
//				type: 'isWed',
//				checked: false
//			},
//			{
//                value: 3,
//				name: '已育',
//				type: 'isWed',
//				checked: false
//			}
//		]
//	},
//	{
//        title: '年龄',
//		type: 'age',
//		item: [
//			{
//                value: 0,
//				name: '其他',
//				type: 'age',
//				checked: true
//			},
//			{
//                value: 1,
//				name: '90后',
//				type: 'age',
//				checked: false
//			},
//			{
//                value: 2,
//				name: '80后',
//				checked: false,
//				type: 'age'
//			},
//			{
//                value: 3,
//				name: '70后',
//				type: 'age',
//				checked: false
//			},
//			{
//                value: 4,
//				name: '00后',
//				type: 'age',
//				checked: false
//			}
//		]
//	},
//	{
//        title: '职业',
//		type: 'occupation',
//		item: [
//			{
//                value: 0,
//				name: '自由职业',
//				type: 'occupation',
//				checked: true
//			},
//			{
//                value: 1,
//				name: '学生',
//				type: 'occupation',
//				checked: false
//			},
//
//			{
//                value: 2,
//				name: '上班',
//				type: 'occupation',
//				checked: false
//			},
//			{
//                value: 3,
//				name: '辣妈',
//				type: 'occupation',
//				checked: false
//			}
//		]
//	}
//];
        $list=[
            'cate'=>[
                ['id'=>-1,'title'=>'辣妈','type'=>'category','checked'=>false],
                ['id'=>0,'title'=>'辣妈','type'=>'category','checked'=>false],
                ['id'=>1,'title'=>'图书','type'=>'category','checked'=>false],
                ['id'=>2,'title'=>'零食','type'=>'category','checked'=>false],
            ],
            'tag'=>[
                'category'=>'-1,0,2',
                'occupation'=>'0',
//                'isWed'=>'',
//                'gender'=>'',
//                'age'=>'',
            ],
        ];
        return $list;
    }

}